<?php

function gen_mensaplan($urlindex) {
    //Tag ermitteln und uebersetzen
    $day = getdate();
    switch ($day['weekday']) {
        case 'Monday': $day['weekday'] = 'Montag';
            break;
        case 'Tuesday': $day['weekday'] = 'Dienstag';
            break;
        case 'Wednesday': $day['weekday'] = 'Mittwoch';
            break;
        case 'Thursday': $day['weekday'] = 'Donnerstag';
            break;
        case 'Friday': $day['weekday'] = 'Freitag';
            break;
        case 'Saturday': $day['weekday'] = 'Samstag';
            break;
    }
    //Url prefix fuer links
    $url = "http://www.trivalg.de/mensa";
    //xml object der xml datei erstellen
    $xml = simplexml_load_file($urlindex);

    //links auslesen
    foreach ($xml->xpath('//link') as $link) {
        $xmlwo = simplexml_load_file($url . $link);
        foreach ($xmlwo->tag as $tag) {
            //Automatisches Anzeigen des aktuellen Menues 
            if ($day['weekday'] == $tag['value']) {
                echo "<div data-role='collapsible' data-content-theme='a' data-collapsed='false'><h3>" . $tag['value'] . "</h3>";
            }
            else
                echo "<div data-role='collapsible' data-content-theme='a'><h3>" . $tag['value'] . "</h3>";
            echo "<strong>Mittagsmensa</strong><p>";
            if($xmlwo->tag->mittag->essen->count() == 0)
                echo "Mensa geschlossen";
            else {
                foreach ($xmlwo->tag->mittag->essen as $essen)
                    echo $essen->name."<br>";
            }
            echo "</p>";
            echo "<strong>Abendmensa</strong><p>";
            if($xmlwo->tag->abend->essen->count() == 0)
                echo "Mensa geschlossen";
            else {
                foreach ($xmlwo->tag->abend->essen as $essen)           
                    echo $essen->name."<br>";
            }
            echo "</p></div>";
            
        }
    }
}
?>